<template>
  <div class="bean-trans-wrap">
    <div class="account_pic">
      <img src="../../../assets/images/account_index.png" />
    </div>
    <p class="account_balance">￥{{ysMoney}}</p>
    <div class="default-bottom-btn">
      <van-button type="custom-primary" size="large" block @click="toApplyWidthDraw">提现</van-button>
    </div>
  </div>
</template>

<script>
import { Toast, Button } from "vant";
import { getMessageBox } from "@/assets/js/utils";
import { getYsolMoney, checkCanCashOut } from "@/api/api";
export default {
  name: "accountindex",
  components: {
    vanButton: Button,
  },
  data() {
    return {
      ysMoney: "",
      cash_money: "",
    };
  },
  created() {
    this.getMoneyInfo();
  },
  methods: {
    // 获取当前账户信息
    getMoneyInfo() {
      Toast.loading({
        message: "加载中...",
        forbidClick: true,
        duration: 0,
      });
      getYsolMoney()
        .then((res) => {
          Toast.clear();
          if (res.code == 200000) {
            this.ysMoney = res.data.money;
            this.cash_money = res.data.cash_money;
          } else {
            Toast(res.msg);
          }
        })
        .catch(Toast.clear());
    },
    // 提现
    toApplyWidthDraw() {
      if (this.ysMoney <= 0) {
        getMessageBox("当前余额不足，无法提现");
        return false;
      }
      Toast.loading({
        message: "加载中...",
        forbidClick: true,
        duration: 0,
      });
      //判断是否可提现
      checkCanCashOut()
        .then((res) => {
          Toast.clear();
          if (res.code == 200000) {
            this.$router.push({
              path: "/widthDrawApply",
              query: {
                cash_money: this.cash_money,
              },
            });
          } else if (res.code == 320006) {
            getMessageBox(
              "未完成实名认证和绑卡，请在”轶善在线”公众号，完成实名认证和银行卡绑定后，再进行转让操作。"
            );
          } else if (res.code == 310018) {
            getMessageBox(
              "未完成银行卡绑定，请在”轶善在线”公众号，完成银行卡绑定后，再进行转让操作。"
            );
          } else {
            getMessageBox(res.msg);
          }
        })
        .catch((err) => {
          Toast.clear();
        });
    },
  },
};
</script>

<style scoped lang="less">
.bean-trans-wrap {
  .default-bottom-btn {
    margin-top: 50px;
  }
  margin-bottom: 100px;
  width: 375px;
  overflow: hidden;
  min-height: calc(100% - 100px);
  background: #fff;
  .lnie-place {
    width: 100%;
    height: 10px;
    background: rgba(241, 246, 253, 1);
  }

  overflow: hidden;
  position: relative;
  .account_pic {
    height: 56px;
    width: 51px;
    margin: 60px auto 0;
    img {
      height: 56px;
      width: auto;
    }
  }

  .account_balance {
    text-align: center;
    font-size: 40px;
    color: rgb(51, 51, 51);
    margin: 32px 20px 0;
    white-space: normal;
    font-family: DingMedium;
  }
}
.look {
  position: absolute;
  top: 20px;
  right: 40px;
  font-size: 32px;
}
</style>
